package com.taru.university.service.impl;

import com.github.pagehelper.PageHelper;
import com.taru.university.mapper.CommentMapper;
import com.taru.university.mapper.DiseaseMapper;
import com.taru.university.model.Comment;
import com.taru.university.model.Disease;
import com.taru.university.service.DiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DiseaseServiceImpl implements DiseaseService {
    @Autowired
    DiseaseMapper diseaseMapper;
    @Autowired
    CommentMapper commentMapper;

    @Override
    public List<Disease> queryDisease(String diseaseSort, int pageNum, int pageSize) {
       List<Disease> list = diseaseMapper.queryDisease( diseaseSort);
        PageHelper.startPage(pageNum, pageSize);
       for(Disease diseaseList: list){
           List<Comment> commentList= commentMapper.queryCommentByArticleId(diseaseList.getDiseaseId());
           diseaseList.setCommentList(commentList);
       }
        return list;
    }

    @Override
    public Disease queryDiseaseById(String diseaseId) {
        return diseaseMapper.queryDiseaseById(diseaseId);
    }

    @Override
    public void insertDisease(Disease disease) {
        diseaseMapper.insertDisease(disease);
    }

    @Override
    public void deleteDisease(String diseaseId) {
        diseaseMapper.deleteDisease(diseaseId);
    }

    @Override
    public List<Disease> queryDiseaseByTitle(String diseaseTitle, int pageNum, int pageSize) {
        List<Disease> list = diseaseMapper.queryDiseaseByTitle(diseaseTitle);
        PageHelper.startPage(pageNum, pageSize);
        for(Disease diseaseList: list){
            List<Comment> commentList= commentMapper.queryCommentByArticleId(diseaseList.getDiseaseId());
            diseaseList.setCommentList(commentList);
        }

        return list;
    }

    @Override
    public List<Disease> queryDiseaseByStatue(int pageNum, int pageSize) {
        List<Disease> list = diseaseMapper.queryDiseaseByStatue();
        PageHelper.startPage(pageNum, pageSize);
        for(Disease diseaseList: list){
            List<Comment> commentList= commentMapper.queryCommentByArticleId(diseaseList.getDiseaseId());
            diseaseList.setCommentList(commentList);
        }
        return list;
    }

    @Override
    public List<Disease> queryDiseaseSort(String diseaseSort) {
        return diseaseMapper.queryDisease(diseaseSort);
    }

    @Override
    public List<Disease> queryDiseaseByTitleLen(String diseaseTitle) {
        return  diseaseMapper.queryDiseaseByTitle(diseaseTitle);
    }

    @Override
    public List<Disease> queryDiseaseByStatueLen() {
        return diseaseMapper.queryDiseaseByStatue();
    }
}
